package cn.szq.concurrent.thread.stop;

import java.util.concurrent.BlockingQueue;

/**
 * @ClassName: Producter
 * @Description: 生产者
 * @Author: szq
 * @Date: 2021-09-26 18:09:54
 */
public class Producter implements Runnable{

    public volatile boolean cancled = false;

    BlockingQueue storage;

    public Producter(BlockingQueue storage){
        this.storage = storage;
    }

    @Override
    public void run() {
        int num = 0;
        try{
            while (num <= 100000 && !cancled){
                if (num % 50 == 0){
                    storage.put(num);
                    System.out.println(num + "是50的倍数，被放入到仓库中。");
                }
                num ++;
            }
        }catch (InterruptedException e){
            e.printStackTrace();
        }finally {
            System.out.println("生产者结束运行。");
        }
    }
}
